package com.hzqy.web.ac.epg;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hzqy.commons.utils.ExcelUtil;
import com.hzqy.commons.utils.ExcelUtil.MyEntry;
import com.hzqy.service.epg.AcIntegralService;
import com.hzqy.service.system.SysVoProcessServiceBeen;
import com.hzqy.web.vo.activity.ActivityVoteUserVo;
import com.hzqy.web.vo.epg.AcIntegralVo;

@Controller
@RequestMapping("/integral")
public class AcIntegralAction {
	@Resource
	private AcIntegralService acIntegralService;
	@Resource
	private SysVoProcessServiceBeen voProcessServiceBean;
	/**
	 * 个人排名
	 * @return
	 */
	@RequestMapping("/selectIntegral")
	@ResponseBody
	public Object selectIntegral(AcIntegralVo aiv,int page,int rows){
		Map<String,Object> map = new HashMap<String, Object>();
		map = acIntegralService.selectIntegral(aiv,page,rows);
		return map;
	}
	/**
	 * 查询所有区，街道
	 * @return
	 */
	@RequestMapping("/selectArea")
	@ResponseBody
	public Object selectArea(AcIntegralVo aiv) {
		Map<String,Object> map = new HashMap<String, Object>();
		map = acIntegralService.selectArea(aiv);
		return map;
	}
	/**
	 * 社区排名
	 */
	@RequestMapping("/selectCommunityIntegral")
	@ResponseBody
	public Object selectCommunityIntegral(AcIntegralVo aiv,int page,int rows){
		Map<String,Object> map = new HashMap<String, Object>();
		map = acIntegralService.selectCommunityIntegral(aiv,page,rows);
		return map;
	}
	//社区排名导出
	@RequestMapping(value="/community_excel")
	@ResponseBody
	public void community(AcIntegralVo aiv,HttpServletResponse response)throws IOException {
		Map<String,Object> map = new HashMap<String, Object>();
		map = acIntegralService.selectCommunityIntegral(aiv,1,9999);
		List<AcIntegralVo> list=new ArrayList<AcIntegralVo>();
		list = (List<AcIntegralVo>)map.get("rows");
		voProcessServiceBean.voProcess(list);
		List<MyEntry<String, String>> excelCpHeader=new ArrayList<MyEntry<String, String>>();
		excelCpHeader.add(new MyEntry<String,String>("aiv_rownum","排名"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_saName","区"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_sasName","社区"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_integralNum","社区积分"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_likeNum","社区点赞数"));
		boolean flag=ExcelUtil.generateExcel(list, excelCpHeader, response);
	}
	
	//个人积分导出
	@RequestMapping(value="/integral_excel")
	@ResponseBody
	public void integralExcelList(AcIntegralVo aiv,HttpServletResponse response)throws IOException {
		Map<String,Object> map = new HashMap<String, Object>();
		map = acIntegralService.selectIntegral(aiv,1,9999);
		List<AcIntegralVo> list=new ArrayList<AcIntegralVo>();
		list = (List<AcIntegralVo>)map.get("rows");
		voProcessServiceBean.voProcess(list);
		List<MyEntry<String, String>> excelCpHeader=new ArrayList<MyEntry<String, String>>();
		excelCpHeader.add(new MyEntry<String,String>("aiv_rownum","排名"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_name","名称"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_integralNum","个人积分"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_phone","用户手机号"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_serviceId","业务账号"));
		excelCpHeader.add(new MyEntry<String,String>("createTime","报名时间"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_sasName","社区"));
		excelCpHeader.add(new MyEntry<String,String>("aiv_sasDesc","社区介绍"));
		boolean flag=ExcelUtil.generateExcel(list, excelCpHeader, response);
	}
	
	//社区积分增加点赞数

	@RequestMapping("/insertCommunityLike")
	@ResponseBody
	public Object insertCommunityLike(int Community,int vote){
		Map<String,Object> map = new HashMap<String, Object>();
		ActivityVoteUserVo acvotesuer = new ActivityVoteUserVo();
		acvotesuer.setF_avu_contentid(Community);
		acvotesuer.setF_avu_votenum(vote);
		acvotesuer.setF_avu_activityid("47");
		acvotesuer.setF_avu_serverid("123");
		acvotesuer.setF_avu_type(2);
		acvotesuer.setF_avu_source(0);
		acvotesuer.setF_avu_memo("后台增票");
		acvotesuer.setF_avu_obligate1(0);
		acvotesuer.setF_avu_obligate2("0");
		int result = acIntegralService.insertACLikeVote(acvotesuer);
		return result;
	}

}
